$(function () {
    //登录
    $("#login").click(function () {
        $("#count_span").html("");
        $("#password_span").html("");
        //获取用户名和id
        var name = $("#count").val().trim();
        var password = $("#password").val().trim();
        // console.log(name,password);
        var ok = true;
        if (name == ""){
            ok = false;
            $("#count_span").html("用户名为空");
        }
        if (password == "") {
            ok = false;
            $("#password_span").html("密码为空");
        }
        //发送ajax请求
        if (ok){
            $.ajax({
                url: "http://localhost:80/emp/login.do",
                type: "post",
                dataType: "json",
                data: {"ename": name, "pwd": password},
                success: function (result) {
                    //将id放入cookie
                    if (result.status == 0) {
                        var id = result.data.eid;
                        addCookie("id", id, 1);
                        console.log(id)
                        alert(result.msg)
                        window.location.href = "main.jsp"
                    }else if(result.status == 1){
                        alert(result.msg)
                    }else if (result.status == 2){
                        alert(result.msg)
                    }
                },
                error: function(){
                    alert("登录失败！")
                }
            })
        }
    })

})
